package com.xy.bioapi.aspect;

import com.xy.bioapi.utils.SignUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Caeyer on 2017/7/10.
 */
@Aspect
@Component
public class HttpAspect {

    @Pointcut("execution(public * com.xy.bioapi.controller.ChipInterfaceController.*(..))")
    public void log(){

    }

    @Before("log()")
    public void doBefore(JoinPoint joinPoint){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        SignUtil signUtil = new SignUtil();
        signUtil.compareSign(request);

        String field = request.getParameter("field");
        String sign = request.getParameter("sign");

        System.out.println("field = "+field+",sign = "+sign);

    }

    @After("log()")
    public void doAfter(){

    }
}
